package com.whg.shiro.exception;

import com.whg.shiro.domain.SimpleResult;
import com.whg.shiro.domain.common.JsonData;
import org.apache.shiro.authz.UnauthorizedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author whg
 * @create 2022/10/13 16:28
 * @description：
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    public JsonData processUnauthorizedException(Exception e){
        logger.error("UnauthorizedException Error",e);
        JsonData jsonData = JsonData.buildError("未授权",403);
        return jsonData;
    }
}
